
package sistemachamados.view;
import classes.*;

import classes.CategoriaChamado;
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default;
import java.util.ArrayList;
import javax.swing.JDialog;
import javax.swing.table.DefaultTableModel;
import java.util.*;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.DefaultComboBoxModel;


public class FormCategoriaChamado extends javax.swing.JInternalFrame {

    private Usuario usuarioLogado;

    public FormCategoriaChamado(Usuario usuarioLogado) {
        initComponents();
        this.usuarioLogado = usuarioLogado;
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        btnPesquisar = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        cmbCategoria = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        btnExcluir = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCategoriaChamados = new javax.swing.JTable();
        btnIncluir = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        txtCategoria = new javax.swing.JTextField();
        btnCancelar = new javax.swing.JButton();
        cmbTempMax = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cmbTempMin = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setBorder(null);
        setClosable(true);
        setFrameIcon(null);
        setInheritsPopupMenu(true);
        setMinimumSize(new java.awt.Dimension(990, 470));
        setPreferredSize(new java.awt.Dimension(990, 470));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "FILTROS DE PESQUISA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Showcard Gothic", 0, 16))); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(FormCategoriaChamado.class);
        jPanel1.setFont(resourceMap.getFont("jPanel1.font")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setOpaque(false);

        jLabel1.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel1.setText("Categoria");
        jLabel1.setName("jLabel1"); // NOI18N

        btnPesquisar.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnPesquisar.setText("Pesquisar");
        btnPesquisar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnPesquisar.setName("btnPesquisar"); // NOI18N
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        btnLimpar.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnLimpar.setText("Limpar");
        btnLimpar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnLimpar.setName("btnLimpar"); // NOI18N
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        cmbCategoria.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N
        cmbCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas" }));
        cmbCategoria.setName("cmbCategoria"); // NOI18N
        cmbCategoria.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmbCategoriaMouseClicked(evt);
            }
        });
        cmbCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCategoriaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 362, Short.MAX_VALUE)
                .addComponent(btnPesquisar)
                .addGap(18, 18, 18)
                .addComponent(btnLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btnLimpar)
                    .addComponent(btnPesquisar)
                    .addComponent(cmbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 20, 960, 80);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CATEGORIAS CHAMADOS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Showcard Gothic", 0, 16))); // NOI18N
        jPanel2.setFont(new java.awt.Font("Showcard Gothic", 0, 16));
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setOpaque(false);
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnExcluir.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 16)); // NOI18N
        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemachamados/view/resources/Xicon.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnExcluir.setName("btnExcluir"); // NOI18N
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });
        jPanel2.add(btnExcluir, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 160, 110, -1));

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblCategoriaChamados.setFont(new java.awt.Font("Tahoma", 0, 12));
        tblCategoriaChamados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblCategoriaChamados.setCellSelectionEnabled(true);
        tblCategoriaChamados.setName("tblCategoriaChamados"); // NOI18N
        tblCategoriaChamados.getTableHeader().setResizingAllowed(false);
        tblCategoriaChamados.getTableHeader().setReorderingAllowed(false);
        tblCategoriaChamados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblCategoriaChamadosMouseClicked(evt);
            }
        });
        tblCategoriaChamados.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                tblCategoriaChamadosComponentShown(evt);
            }
        });
        tblCategoriaChamados.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tblCategoriaChamadosKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tblCategoriaChamados);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 40, 720, 100));

        btnIncluir.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 16)); // NOI18N
        btnIncluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemachamados/view/resources/ViconUsado.png"))); // NOI18N
        btnIncluir.setText("Incluir");
        btnIncluir.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnIncluir.setName("btnIncluir"); // NOI18N
        btnIncluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirActionPerformed(evt);
            }
        });
        jPanel2.add(btnIncluir, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 160, 110, -1));

        btnAlterar.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 16)); // NOI18N
        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemachamados/view/resources/!icon.png"))); // NOI18N
        btnAlterar.setText("Alterar");
        btnAlterar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnAlterar.setName("btnAlterar"); // NOI18N
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });
        jPanel2.add(btnAlterar, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 160, 110, -1));

        getContentPane().add(jPanel2);
        jPanel2.setBounds(10, 104, 960, 210);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "INCLUIR / ALTERAR CATEGORIA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Showcard Gothic", 0, 16))); // NOI18N
        jPanel3.setFont(new java.awt.Font("Tempus Sans ITC", 1, 24));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setOpaque(false);

        txtCategoria.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtCategoria.setName("txtCategoria"); // NOI18N

        btnCancelar.setFont(new java.awt.Font("Berlin Sans FB Demi", 0, 14));
        btnCancelar.setText("Cancelar");
        btnCancelar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        btnCancelar.setName("btnCancelar"); // NOI18N
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        cmbTempMax.setFont(new java.awt.Font("Century Gothic", 0, 14));
        cmbTempMax.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "15", "30", "60", "120", "180", "240", "300", "360", "420", "480" }));
        cmbTempMax.setName("cmbTempMax"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel6.setText("Tempo Max.");
        jLabel6.setName("jLabel6"); // NOI18N

        cmbTempMin.setFont(new java.awt.Font("Century Gothic", 0, 14));
        cmbTempMin.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "15", "30", "60", "120", "180", "240", "300", "360", "420", "480" }));
        cmbTempMin.setName("cmbTempMin"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel4.setText("Tempo Min.");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Gautami", 3, 16));
        jLabel3.setText("Categoria");
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbTempMin, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbTempMax, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(111, 111, 111))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(cmbTempMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar)
                    .addComponent(txtCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbTempMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        getContentPane().add(jPanel3);
        jPanel3.setBounds(10, 320, 960, 80);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemachamados/view/resources/FORM PRINCIPAL (FUNDOPANEL).png"))); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        jLabel5.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jLabel5ComponentShown(evt);
            }
        });
        getContentPane().add(jLabel5);
        jLabel5.setBounds(10, 0, 970, 460);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblCategoriaChamadosComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_tblCategoriaChamadosComponentShown
    
    }//GEN-LAST:event_tblCategoriaChamadosComponentShown

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        btnIncluir.setEnabled(false);
        btnAlterar.setEnabled(false);
        btnExcluir.setEnabled(false);
        atualizarCategoriaChamado();
        preencherCombo();
        verificaPermissao();
    }//GEN-LAST:event_formComponentShown

    public void verificaPermissao()
    {
        ArrayList<Acesso> listPermissao = usuarioLogado.getListAcessos();

      if(listPermissao != null){
        for (int i = 0; i < listPermissao.size(); i++) {
            String descr_pemissao=listPermissao.get(i).getDescr();

            if( descr_pemissao.equals("Incluir") ){
                btnIncluir.setEnabled(true);
            }
            if( descr_pemissao.equals("Alterar") ){
                btnAlterar.setEnabled(true);
            }
            if( descr_pemissao.equals("Excluir") ){
                btnExcluir.setEnabled(true);
            }
        }
      }
    }
    private void btnIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirActionPerformed
        // TODO add your handling code here:
        CategoriaChamado categoriaChamado = new CategoriaChamado();
        if (txtCategoria.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Preencha a Categoria.");
        }else{
            categoriaChamado.setDescr(txtCategoria.getText());
            Double tmpMax = Double.parseDouble(((String)cmbTempMax.getSelectedItem()));
            categoriaChamado.setTempoMaximoAtend(tmpMax);
            Double tmpMin = Double.parseDouble(((String)cmbTempMin.getSelectedItem()));
            categoriaChamado.setTempoMinimoAtend(tmpMin);
            if((categoriaChamado.salvar(usuarioLogado))==true){
                JOptionPane.showMessageDialog(null, "Inclusão bem sucedida.");
            }else{
                JOptionPane.showMessageDialog(null, "Inclusão mal sucedida, contate o Administrador!");
            }
            limparCampos();
            atualizarCategoriaChamado();
            preencherCombo();
        }
 
    }//GEN-LAST:event_btnIncluirActionPerformed



    private void preencherCombo(){
        CategoriaChamado novaCategoriaChamado = new CategoriaChamado();
        ArrayList<CategoriaChamado> listCategoriaChamados = novaCategoriaChamado.selecionar() ;

        if(listCategoriaChamados != null)
        {
            cmbCategoria.setModel(new DefaultComboBoxModel(listCategoriaChamados.toArray()));
        }
        else
        {
            JOptionPane.showMessageDialog(this, "Houve um erro ao carregar as categorias. \n"+
                                                " Até resolver este problema, não será possível incluir usuários no sistema.",
                                                "Erro ao carregar as categorias...",
                                                JOptionPane.ERROR_MESSAGE);
        }
    }
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        limparCampos();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void tblCategoriaChamadosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblCategoriaChamadosKeyPressed
        // TODO add your handling code here:
        preecherCampos();
    }//GEN-LAST:event_tblCategoriaChamadosKeyPressed

    private void tblCategoriaChamadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblCategoriaChamadosMouseClicked
        // TODO add your handling code here:
        preecherCampos();
    }//GEN-LAST:event_tblCategoriaChamadosMouseClicked

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        // TODO add your handling code here:
         if (txtCategoria.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Selecione uma Categoria.");
        }else{

            if(tblCategoriaChamados.getRowCount() > 0){
                int codCategoriaChamado = Integer.parseInt(tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 0).toString());
                CategoriaChamado categoriaChamado = new CategoriaChamado();
                categoriaChamado.setId(codCategoriaChamado);
                if((categoriaChamado.deletar())==true){
                    JOptionPane.showMessageDialog(null, "Exclusão bem sucedida.");
                }else{
                    JOptionPane.showMessageDialog(null, "Exclusão mal sucedida, verifique se a categoria foi selecionada da tabela!");
                }
                limparCampos();
                atualizarCategoriaChamado();
                preencherCombo();
            }
        }
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        // TODO add your handling code here:
        CategoriaChamado categoriaChamado = new CategoriaChamado();
        if (txtCategoria.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Selecione uma Categoria.");
        }else{
            categoriaChamado.setId((Integer)(tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 0)));
            categoriaChamado.setDescr(txtCategoria.getText());
            Double tmpMax = Double.parseDouble(((String)cmbTempMax.getSelectedItem()));
            categoriaChamado.setTempoMaximoAtend(tmpMax);
            Double tmpMin = Double.parseDouble(((String)cmbTempMin.getSelectedItem()));
            categoriaChamado.setTempoMinimoAtend(tmpMin);
            if((categoriaChamado.alterar(usuarioLogado))==true){
                JOptionPane.showMessageDialog(null, "Ateração bem sucedida.");
            }else{
                JOptionPane.showMessageDialog(null, "Ateração mal sucedida, verifique se a categoria foi selecionada da tabela!");
            }
            limparCampos();
            atualizarCategoriaChamado();
            preencherCombo();
        }
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void cmbCategoriaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmbCategoriaMouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_cmbCategoriaMouseClicked

    private void cmbCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCategoriaActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_cmbCategoriaActionPerformed

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        // TODO add your handling code here:
        if(cmbCategoria.getItemCount() > 0)
        {
            String categoria = (cmbCategoria.getSelectedItem().toString());
            DefaultTableModel modelo = new DefaultTableModel();
            tblCategoriaChamados.setModel(modelo);
            modelo.addColumn("Codigo");
            modelo.addColumn("Descrição");
            modelo.addColumn("Temp. Min. Atendimento");
            modelo.addColumn("Temp. Max. Atendimento");
            ArrayList<CategoriaChamado> vetCategoriaChamados=CategoriaChamado.pesquisar(categoria);
            for(int i=0; i < vetCategoriaChamados.size();i++)
            {
                Object[] linha = new Object[4];
                linha[0]=vetCategoriaChamados.get(i).getId();
                linha[1]=vetCategoriaChamados.get(i).getDescr();
                linha[2]=vetCategoriaChamados.get(i).getTempoMinimoAtend();
                linha[3]=vetCategoriaChamados.get(i).getTempoMaximoAtend();

                modelo.insertRow(modelo.getRowCount(), linha);
            }
        }
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
        limparCampos();
    }//GEN-LAST:event_btnLimparActionPerformed

    private void jLabel5ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jLabel5ComponentShown
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel5ComponentShown

    public void preecherCampos(){
        if(tblCategoriaChamados.getRowCount() > 0){
           String codCategoriaChamado = tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 0).toString();
           String descricao = tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 1).toString();
           txtCategoria.setText(descricao);
           cmbTempMin.setSelectedIndex((Integer)(tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 2)));
           cmbTempMax.setSelectedItem(tblCategoriaChamados.getValueAt(tblCategoriaChamados.getSelectedRow(), 3).toString());
        }
    }

    public void limparCampos(){
        atualizarCategoriaChamado();
        txtCategoria.setText("");
        cmbTempMax.setSelectedIndex(0);
        cmbTempMin.setSelectedIndex(0);
        cmbCategoria.setSelectedIndex(0);
    }

    private void atualizarCategoriaChamado(){
        DefaultTableModel modelo = new DefaultTableModel();
        tblCategoriaChamados.setModel(modelo);
        modelo.addColumn("Codigo");
        modelo.addColumn("Descrição");
        modelo.addColumn("Temp. Min. Atendimento");
        modelo.addColumn("Temp. Max. Atendimento");
        ArrayList<CategoriaChamado> vetCategoriaChamados=CategoriaChamado.selecionar();
        for(int i=0; i < vetCategoriaChamados.size();i++)
        {
            Object[] linha = new Object[4];
            linha[0]=vetCategoriaChamados.get(i).getId();
            linha[1]=vetCategoriaChamados.get(i).getDescr();
            linha[2]=vetCategoriaChamados.get(i).getTempoMinimoAtend();
            linha[3]=vetCategoriaChamados.get(i).getTempoMaximoAtend();

            modelo.insertRow(modelo.getRowCount(), linha);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnIncluir;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JComboBox cmbCategoria;
    private javax.swing.JComboBox cmbTempMax;
    private javax.swing.JComboBox cmbTempMin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblCategoriaChamados;
    private javax.swing.JTextField txtCategoria;
    // End of variables declaration//GEN-END:variables

}
